﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ClassManager_Addbarnd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            RECORDID.Text = "";
            String rID = Page.Request["ID"];
            if (rID != null && rID != "")
            {
                EntityOprHelper helper = new EntityOprHelper();
                T_BARND add = helper.GetEntityByWhere<T_BARND>(" where ID=" + rID + "");
                if (add != null)
                {
                    pName.Text = add.NAME;
                    RECORDID.Text = add.ID.ToString();
                }
            }

        }
    }
    protected void Submit_Click(object sender, EventArgs e)
    {
        String userNames = pName.Text;
        if (userNames == "")
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('请输入品牌名称')", true);
            return;
        }
        EntityOprHelper helper = new EntityOprHelper();
   
        if (RECORDID.Text != "")
        {
            T_BARND address = new T_BARND();
            address.NAME = userNames;
            address.ID =Convert.ToInt32(RECORDID.Text);

            bool b1 = helper.EditEntity<T_BARND>(address);
            if (b1)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('修改成功')", true);
                pName.Text = "";
                RECORDID.Text = "";

            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('修改失败')", true);
            }

            return;
        }




        T_BARND oldUser = helper.GetEntityByWhere<T_BARND>(" where name='" + userNames + "'");
        if (oldUser != null)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('品牌名称已经存在!')", true);
            return;
        }

        T_BARND _address = new T_BARND();
        _address.NAME = userNames;
        _address.BARNDID = System.Guid.NewGuid().ToString("N").ToUpper();


        bool b = helper.AddEntity<T_BARND>(_address);
        if (b)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('添加成功')", true);
            pName.Text = "";
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('添加失败')", true);
        }
    }
}
